package com.shop2cn.iapi.productcategory.testcase;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonElement;
import com.shop2cn.iapi.productcategory.parameter.BrandAliasDto;
import com.shop2cn.iapi.productcategory.parameter.BrandCategoryDto;
import com.shop2cn.iapi.productcategory.parameter.BrandDto;
import com.shop2cn.iapi.productcategory.parameter.CountryDto;
import com.shop2cn.iapi.productcategory.parameter.GetBrandByIdBean;
import com.shop2cn.iapi.productcategory.parameter.SaveBrandBean;
import com.shop2cn.iapi.productcategory.service.SaveBrandCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.mongo.BuyerProductShop2cnWapper;
import com.ymttest.utils.TestDataManager;
/**
*保存&修改品牌信息（后台）
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SaveBrand{
	private static SaveBrandBean savebrandBean;
	private static SaveBrandCall savebrandCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("保存&修改品牌信息（后台）");
	}

	@Before
	public void caseUp() {
		savebrandBean=new SaveBrandBean();
		savebrandCall=new SaveBrandCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(savebrandCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveBrand_001() {
		Logger.start(true,"保存&修改品牌信息（后台）");
		try {
			Integer abs = Math.abs(TestDataManager.getRandomIntNum(10));
			savebrandBean.setCnName("测试品牌005号");
			savebrandBean.setEnName(abs.toString());
			savebrandBean.setKeyWord("T");
			savebrandBean.setCountryId(004);
			savebrandBean.setDefaultName(1);
			savebrandBean.setType(2);
			BrandCategoryDto brandCategoryDto = new BrandCategoryDto();
			brandCategoryDto.setCategoryEnName("hhahhha");
			brandCategoryDto.setCategoryId(10086);
			brandCategoryDto.setCategoryName("书籍是人lei的阶梯");
			brandCategoryDto.setCategoryPath("书籍 -> 四大名著 -> 西游记");
			brandCategoryDto.setLevel(2);
			brandCategoryDto.setMasterCategoryId(10881);
			List<BrandCategoryDto> categoryList = new ArrayList<BrandCategoryDto>();
			categoryList.add(brandCategoryDto);
			
			savebrandBean.setCategoryList(categoryList);
			CountryDto countryDto = new CountryDto();
			countryDto.setContinentName("湖北省");
			countryDto.setCountryId(001);
			countryDto.setCountryName("中国");
			List<CountryDto> comnCountryList = new ArrayList<CountryDto>();
			comnCountryList.add(countryDto);
			
			savebrandBean.setComnCountryList(comnCountryList);
			savebrandBean.setDescription("这是一条测试数据");
			savebrandBean.setLogoUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1533271935029&di=c20549998621dfd6ee14b41b92db97fa&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F018373556848c8000001271679582d.jpg");
			savebrandBean.setBannerUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1533271995519&di=9f040e778034bf7381c75488e063d03f&imgtype=0&src=http%3A%2F%2Fwww.jituwang.com%2Fuploads%2Fallimg%2F140428%2F259428-14042PS62466.jpg");
			BrandAliasDto brandAliasDto = new BrandAliasDto();
			brandAliasDto.setId(0001);
			brandAliasDto.setName("玄幻之祖");
			List<BrandAliasDto> aliasList = new ArrayList<BrandAliasDto>();
			aliasList.add(brandAliasDto);
			
			savebrandBean.setAliasList(aliasList);
			savebrandBean.setFounder("孙悟空");
			savebrandBean.setUpdatUser("猪八戒");
			
			savebrandCall.setData(savebrandBean);
			savebrandCall.callService();			
			String Code = savebrandCall.getString("Code");
			Logger.verifyEquals("200", Code, "验证Code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveBrand_002() {
		Logger.start(true,"保存&修改品牌信息（后台）");
		try {
			savebrandBean.setId(2155);
			savebrandBean.setCnName("测试品牌002号");
			savebrandBean.setEnName("TestBrand_001");
			savebrandBean.setKeyWord("T");
			savebrandBean.setCountryId(001);
			savebrandBean.setDefaultName(1);
			savebrandBean.setType(1);
			BrandCategoryDto brandCategoryDto = new BrandCategoryDto();
			brandCategoryDto.setCategoryEnName("xiyouji");
			brandCategoryDto.setCategoryId(1086);
			brandCategoryDto.setCategoryName("书籍");
			brandCategoryDto.setCategoryPath("书籍 -> 四大名著 -> 西游记");
			brandCategoryDto.setLevel(3);
			brandCategoryDto.setMasterCategoryId(1088);
			List<BrandCategoryDto> categoryList = new ArrayList<BrandCategoryDto>();
			categoryList.add(brandCategoryDto);
			
			savebrandBean.setCategoryList(categoryList);
			CountryDto countryDto = new CountryDto();
			countryDto.setContinentName("湖北省");
			countryDto.setCountryId(001);
			countryDto.setCountryName("中国");
			List<CountryDto> comnCountryList = new ArrayList<CountryDto>();
			comnCountryList.add(countryDto);
			
			savebrandBean.setComnCountryList(comnCountryList);
			savebrandBean.setDescription("这是一条测试数据");
			savebrandBean.setLogoUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1533271935029&di=c20549998621dfd6ee14b41b92db97fa&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F018373556848c8000001271679582d.jpg");
			savebrandBean.setBannerUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1533271995519&di=9f040e778034bf7381c75488e063d03f&imgtype=0&src=http%3A%2F%2Fwww.jituwang.com%2Fuploads%2Fallimg%2F140428%2F259428-14042PS62466.jpg");
			BrandAliasDto brandAliasDto = new BrandAliasDto();
			brandAliasDto.setId(0001);
			brandAliasDto.setName("玄幻之祖");
			List<BrandAliasDto> aliasList = new ArrayList<BrandAliasDto>();
			aliasList.add(brandAliasDto);
			
			savebrandBean.setAliasList(aliasList);
			savebrandBean.setFounder("孙悟空");
			savebrandBean.setUpdatUser("猪八戒");
			
			savebrandCall.setData(savebrandBean);
			savebrandCall.callService();		
			Logger.verifyEquals("200", savebrandCall.getString("Code"), "验证Code");
			String BrandId = savebrandCall.getJsonObject().get("Data").getAsJsonObject().get("BrandId").toString();
			Logger.verifyEquals(savebrandBean.getId().toString(), BrandId, "验证id");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}